package cn.cqone.crm.controller;

import cn.cqone.crm.domain.Employee;
import cn.cqone.crm.domain.SetMeal;
import cn.cqone.crm.dto.IdsDto;
import cn.cqone.crm.query.SetMealQuery;
import cn.cqone.crm.service.SetMaelService;
import cn.cqone.crm.utils.JSONResult;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@ResponseBody
@RequestMapping("/setmeal")
@CrossOrigin
@RequiresPermissions("meal:main")
public class SetMealController extends BaseController<SetMeal,Long, SetMealQuery>{
   @Autowired
   private SetMaelService setMaelService;
    //批量购买套餐
    @RequestMapping(value = "/buySetMeal",method = RequestMethod.POST)
    public JSONResult buySetMeal(@RequestBody IdsDto dto){
        try{
            Employee employee =(Employee) SecurityUtils.getSubject().getPrincipal();
            List<Long> ids = dto.getIds();
            setMaelService.buySetMeal(ids,employee);
            return JSONResult.ok();
        }catch (Exception e){
            e.printStackTrace();
            return JSONResult.error("服务器异常,我们正在殴打程序员...");
        }
    }
}
